Template.appBody.onRendered(function(){
	Berth.find().forEach(function(berth){
		if (moment() > moment(berth.endTime)) {
			console.log(berth._id)
			Berth.update({
				_id: berth._id

			}, {
				$set: {
					startTime: null,
					endTime: null,
					userId: null
				}
			});
		};
	});
});

Template.appBody.helpers({
	thisArray: function() {
		return [this];
	},
	// emailLocalPart: function() {
	// 	var email = Meteor.user().emails[0].address;
	// 	return email.substring(0, email.indexOf('@'));
	// },
	activeNavClass: function(name) {
		var current = Router.current();
		var path = current.route._path;
		if (path === name) {
			return 'active';
		}
	},
	updateProfileEmail: function() {
		var email = $("#login-name-link").text().trim().replace(" ▾", "");
		if(!Meteor.user().profile || !Meteor.user().profile.email || Meteor.user().profile.email != email)
		Meteor.users.update({
			_id: Meteor.userId()
		}, {
			$set: {
				'profile.email': email
			}
		});
	}
});